package com.example.photography.adapter.store;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;

import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.CategoryBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 商城分类页
 * 商品图片和名称
 */

public class HomeItemAdapter extends MyBaseAdapter {

    public HomeItemAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public int getCount() {
        if (list != null) {
            return list.size();
        } else {
            return 10;
        }
    }

    @Override
    public View myGetView(int position, View convertView) {
        CategoryBean.DataBean.DataListBean subcategory = (CategoryBean.DataBean.DataListBean) list.get(position);
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.store_item_category, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvName.setText(subcategory.getTitle());
        Uri uri = Uri.parse(subcategory.getImgURL());
        viewHolder.ivIcon.setImageURI(uri);
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.iv_icon)
        SimpleDraweeView ivIcon;
        @BindView(R.id.tvName)
        TextView tvName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
